from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-09 14:02:24.046328
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 09, Mar, 2022
Time: 14:02:29
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.4489
Nobs: 590.000 HQIC: -48.8567
Log likelihood: 7044.96 FPE: 4.66403e-22
AIC: -49.1170 Det(Omega_mle): 4.00930e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.350747 0.067512 5.195 0.000
L1.Burgenland 0.108150 0.040979 2.639 0.008
L1.Kärnten -0.110635 0.021405 -5.169 0.000
L1.Niederösterreich 0.191859 0.085650 2.240 0.025
L1.Oberösterreich 0.123555 0.084543 1.461 0.144
L1.Salzburg 0.257970 0.043438 5.939 0.000
L1.Steiermark 0.035763 0.057337 0.624 0.533
L1.Tirol 0.101899 0.046315 2.200 0.028
L1.Vorarlberg -0.068111 0.040830 -1.668 0.095
L1.Wien 0.016089 0.075196 0.214 0.831
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.051543 0.145241 0.355 0.723
L1.Burgenland -0.037919 0.088160 -0.430 0.667
L1.Kärnten 0.041831 0.046048 0.908 0.364
L1.Niederösterreich -0.204053 0.184261 -1.107 0.268
L1.Oberösterreich 0.458195 0.181878 2.519 0.012
L1.Salzburg 0.282531 0.093449 3.023 0.002
L1.Steiermark 0.113332 0.123351 0.919 0.358
L1.Tirol 0.304528 0.099639 3.056 0.002
L1.Vorarlberg 0.026232 0.087839 0.299 0.765
L1.Wien -0.027082 0.161772 -0.167 0.867
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.200022 0.034430 5.810 0.000
L1.Burgenland 0.088667 0.020899 4.243 0.000
L1.Kärnten -0.007272 0.010916 -0.666 0.505
L1.Niederösterreich 0.239915 0.043680 5.493 0.000
L1.Oberösterreich 0.160886 0.043115 3.732 0.000
L1.Salzburg 0.040101 0.022152 1.810 0.070
L1.Steiermark 0.026073 0.029241 0.892 0.373
L1.Tirol 0.081920 0.023620 3.468 0.001
L1.Vorarlberg 0.053688 0.020823 2.578 0.010
L1.Wien 0.118105 0.038349 3.080 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.119878 0.034434 3.481 0.000
L1.Burgenland 0.042270 0.020901 2.022 0.043
L1.Kärnten -0.013122 0.010917 -1.202 0.229
L1.Niederösterreich 0.170509 0.043684 3.903 0.000
L1.Oberösterreich 0.337873 0.043120 7.836 0.000
L1.Salzburg 0.099849 0.022155 4.507 0.000
L1.Steiermark 0.110090 0.029244 3.765 0.000
L1.Tirol 0.089834 0.023622 3.803 0.000
L1.Vorarlberg 0.060334 0.020825 2.897 0.004
L1.Wien -0.017841 0.038353 -0.465 0.642
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.124841 0.064782 1.927 0.054
L1.Burgenland -0.044197 0.039322 -1.124 0.261
L1.Kärnten -0.045417 0.020539 -2.211 0.027
L1.Niederösterreich 0.135347 0.082186 1.647 0.100
L1.Oberösterreich 0.161156 0.081124 1.987 0.047
L1.Salzburg 0.284679 0.041681 6.830 0.000
L1.Steiermark 0.058906 0.055019 1.071 0.284
L1.Tirol 0.157505 0.044442 3.544 0.000
L1.Vorarlberg 0.096705 0.039179 2.468 0.014
L1.Wien 0.073598 0.072156 1.020 0.308
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.078646 0.050508 1.557 0.119
L1.Burgenland 0.025183 0.030658 0.821 0.411
L1.Kärnten 0.053173 0.016013 3.321 0.001
L1.Niederösterreich 0.188500 0.064077 2.942 0.003
L1.Oberösterreich 0.332715 0.063248 5.260 0.000
L1.Salzburg 0.034827 0.032497 1.072 0.284
L1.Steiermark 0.007115 0.042896 0.166 0.868
L1.Tirol 0.119214 0.034649 3.441 0.001
L1.Vorarlberg 0.065513 0.030546 2.145 0.032
L1.Wien 0.097086 0.056256 1.726 0.084
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.171277 0.060956 2.810 0.005
L1.Burgenland 0.005191 0.037000 0.140 0.888
L1.Kärnten -0.065937 0.019326 -3.412 0.001
L1.Niederösterreich -0.107115 0.077332 -1.385 0.166
L1.Oberösterreich 0.208407 0.076332 2.730 0.006
L1.Salzburg 0.054198 0.039219 1.382 0.167
L1.Steiermark 0.247641 0.051769 4.784 0.000
L1.Tirol 0.499653 0.041817 11.949 0.000
L1.Vorarlberg 0.063910 0.036865 1.734 0.083
L1.Wien -0.074043 0.067894 -1.091 0.275
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161381 0.067637 2.386 0.017
L1.Burgenland -0.002120 0.041055 -0.052 0.959
L1.Kärnten 0.062880 0.021444 2.932 0.003
L1.Niederösterreich 0.165796 0.085808 1.932 0.053
L1.Oberösterreich -0.055620 0.084699 -0.657 0.511
L1.Salzburg 0.208562 0.043518 4.793 0.000
L1.Steiermark 0.138510 0.057443 2.411 0.016
L1.Tirol 0.055733 0.046401 1.201 0.230
L1.Vorarlberg 0.146769 0.040905 3.588 0.000
L1.Wien 0.121298 0.075335 1.610 0.107
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.392087 0.039709 9.874 0.000
L1.Burgenland -0.004032 0.024103 -0.167 0.867
L1.Kärnten -0.021075 0.012590 -1.674 0.094
L1.Niederösterreich 0.200736 0.050377 3.985 0.000
L1.Oberösterreich 0.230294 0.049726 4.631 0.000
L1.Salzburg 0.036927 0.025549 1.445 0.148
L1.Steiermark -0.016887 0.033725 -0.501 0.617
L1.Tirol 0.090308 0.027241 3.315 0.001
L1.Vorarlberg 0.050764 0.024015 2.114 0.035
L1.Wien 0.043678 0.044229 0.988 0.323
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036683 0.102589 0.167265 0.137529 0.095372 0.080169 0.031778 0.209159
Kärnten 0.036683 1.000000 -0.027688 0.131543 0.048264 0.084650 0.443601 -0.067185 0.089425
Niederösterreich 0.102589 -0.027688 1.000000 0.310915 0.118580 0.269629 0.065839 0.151786 0.288419
Oberösterreich 0.167265 0.131543 0.310915 1.000000 0.212465 0.293452 0.166814 0.136141 0.234963
Salzburg 0.137529 0.048264 0.118580 0.212465 1.000000 0.121729 0.091108 0.104784 0.123207
Steiermark 0.095372 0.084650 0.269629 0.293452 0.121729 1.000000 0.133193 0.105684 0.032857
Tirol 0.080169 0.443601 0.065839 0.166814 0.091108 0.133193 1.000000 0.063282 0.151132
Vorarlberg 0.031778 -0.067185 0.151786 0.136141 0.104784 0.105684 0.063282 1.000000 -0.005030
Wien 0.209159 0.089425 0.288419 0.234963 0.123207 0.032857 0.151132 -0.005030 1.000000